package com.wyix.log.service;

import com.wyix.log.domain.Order;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author wangdx
 * @since 2025/8/20
 */
//@Service
public class MilkTeaLogService {
    private String level;
    private boolean printIngredients;
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    // 记录订单创建日志
    public void logOrderCreate(Order order) {
        if ("DETAIL".equals(level)) {
            StringBuilder logBuilder = new StringBuilder();
            logBuilder.append("[订单日志] ")
                    .append(LocalDateTime.now().format(FORMATTER))
                    .append(" 订单创建 - 订单号：").append(order.getOrderNo())
                    .append("，奶茶：").append(order.getTeaType())
                    .append("（").append(order.getSize()).append("）")
                    .append("，价格：").append(order.getPrice()).append("元");

            // 如果需要打印配料，添加配料信息
            if (printIngredients && order.getIngredients() != null && !order.getIngredients().isEmpty()) {
                logBuilder.append("，配料：").append(String.join("+", order.getIngredients()));
            }

            System.out.println(logBuilder.toString());
        } else {
            // 简单日志
            System.out.printf("[订单日志] %s 订单创建 - 订单号：%s，奶茶：%s%n",
                    LocalDateTime.now().format(FORMATTER),
                    order.getOrderNo(),
                    order.getTeaType());
        }
    }

    // 记录订单完成日志
    public void logOrderComplete(Order order) {
        String log = String.format("[订单日志] %s 订单完成 - 订单号：%s",
                LocalDateTime.now().format(FORMATTER),
                order.getOrderNo());
        System.out.println(log);
    }

    // setter方法
    public void setLevel(String level) {
        this.level = level;
    }

    public void setPrintIngredients(boolean printIngredients) {
        this.printIngredients = printIngredients;
    }

}